<template>
    <div class="user">
        <basic-container>
            <avue-crud ref="crud"
                       :page="page"
                       :data="tableData"
                       :table-loading="tableLoading"
                       :option="tableOption"
                       v-model="tableForm"
                       :permission="permissionList"
                       :before-open="beforeOpen"
                       :before-close="beforeClose"
                       @row-save="rowSave"
                       @row-update="rowUpdate"
                       @row-del="rowDelete"
                       @search-change="searchChange"
                       @selection-change="selectChange"
                       @size-change="sizeChange"
                       @current-change="pageChange"
                       @refresh-change="refresh">
                <template slot="logType"
                          slot-scope="scope">
                    <el-tag :type="scope.row.logType==='NORMAL'?'success':'danger'">{{scope.label}}</el-tag>
                </template>
            </avue-crud>
        </basic-container>
    </div>
</template>
<script>
    import {mapGetters} from "vuex";
    import {listPage} from "@/api/sys/sysLog";
    import {tableOption} from '@/const/sys/sysLog';

    export default {
        data() {
            return {
                tableForm: {},
                tableData: [],
                selection: [],
                page: {
                    total: 0, // 总页数
                    currentPage: 1, // 当前页数
                    pageSize: 10, // 每页显示多少条
                    desc: 'create_time',
                },
                searchForm: {},
                tableLoading: false,
                tableOption: tableOption,
                dialogVisible: false,
            }
        },
        watch: {},
        created() {
            this.listPage();
        },
        mounted: function () {
        },
        components: {},
        computed: {
            ...mapGetters(["permission"]),
            permissionList() {
                return {
                    viewBtn: this.vaildData(this.permission['sys:log:list'], false),
                    addBtn: this.vaildData(this.permission['sys:log:save'], false),
                    editBtn: this.vaildData(this.permission['sys:log:update'], false),
                    delBtn: this.vaildData(this.permission['sys:log:delete'], false)
                };
            },
        },
        methods: {
            listPage() {
                this.tableLoading = true;
                this.searchForm = Object.assign(this.searchForm, this.page);
                Object.keys(this.searchForm).forEach((key) => {
                    if (this.validatenull(this.searchForm[key])) {
                        this.searchForm[key] = null;
                    }
                });
                listPage(this.concatLike(this.searchForm, ['content','params']) || {}).then(response => {
                    this.tableData = response.data.records;
                    this.page.total = +response.data.total;
                    this.tableLoading = false;
                });
            },
            rowSave(row, done, loading) {
                loading()
            },
            rowUpdate(row, index, done, loading) {
                loading()
            },
            rowDelete() {

            },
            beforeOpen(show, type) {
                console.log(type);
                show();
            },
            beforeClose(done) {
                done();
            },
            selectChange(row) {
                this.selection = row.map(item => item.id);
            },
            pageChange(currentPage) {
                this.page.currentPage = currentPage;
                this.listPage();
            },
            sizeChange(pageSize) {
                this.page.pageSize = pageSize;
                this.listPage();
            },
            searchChange(params, done) {
                this.page.currentPage = 1;
                this.searchForm = Object.assign({}, params);
                this.listPage();
                done();
            },
            refresh(params) {
                this.searchForm = Object.assign({}, params.searchForm);
                this.listPage();
            },
        }
    }
</script>
